package com.webdrider.servlet.util.parser.blog;

import java.util.logging.Logger;

import com.common.model.abstracts.AbstractResponse;
import com.common.security.exceptions.ParserException;
import com.common.servlet.abstracts.AbstractJSONParser;
import com.webdrider.model.response.blog.GetBlogPostResponse;
import com.webdrider.servlet.util.JSONProtocol;

public class GetBlogPostJSONParser extends AbstractJSONParser {

	@Override
	public String parseResponse(AbstractResponse abstractResponse) throws ParserException {
		GetBlogPostResponse response;
		
		if (abstractResponse instanceof GetBlogPostResponse) {
			response = (GetBlogPostResponse) abstractResponse;
		} else {
			throw new ParserException(ParserException.RESPONSE_MATCH_ERROR);
		}
		
		StringBuilder builder = new StringBuilder();
		
		builder.append(JSONProtocol.OPEN_TAG);
		builder.append(JSONProtocol.ACTION_TAG);
		builder.append(valueToString(response.getRequestAction()));
		builder.append(JSONProtocol.NEW_PARAMETER);
		builder.append(JSONProtocol.DATA_TAG);
		builder.append(valueToObject(response.getPost()));
		builder.append(JSONProtocol.CLOSE_TAG);
		Logger.getAnonymousLogger().severe(builder.toString());
		return builder.toString();
	}

}
